package Visao;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.MaskFormatter;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import Controle.ControleFuncionario;
import Modelo.Funcionario;

import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;

import javax.swing.JFormattedTextField;
import javax.swing.ImageIcon;

public class CadastroFuncionario extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldNome;
	private JFormattedTextField textFieldCpf;
	private JTextField textFieldMatri;
	private JTextField textFieldCargo;
	private Funcionario funci;
	private ControleFuncionario controleFuncionario;
	private JButton btnCadastro;
	private ControleDeTelas telas;
	private JLabel lblNome;

	/**
	 * Launch the application.
	 */
	

	/**
	 * Create the frame.
	 * @throws ParseException 
	 */
	public CadastroFuncionario() throws ParseException {
		telas = new ControleDeTelas();
		funci = new Funcionario();
		controleFuncionario = new ControleFuncionario();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 451, 300);
		setLocationRelativeTo(null);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnInicio = new JMenu("Inicio");
		mnInicio.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				telas.getInicio().setVisible(true);
				dispose();
			}
		});
		menuBar.add(mnInicio);
		
		JMenu mnCadastroAluno = new JMenu("Cadastro Aluno");
		mnCadastroAluno.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				telas.getCadastros().setVisible(true);
				dispose();
			}
		});
		menuBar.add(mnCadastroAluno);
		
		JMenu mnCadastroFuncionario = new JMenu("Cadastro Funcionario");
		menuBar.add(mnCadastroFuncionario);
		
		JMenu mnBusca = new JMenu("Buscas\r\n");
		mnBusca.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				telas.getBusca().setVisible(true);
				dispose();
			}
		});
		menuBar.add(mnBusca);
		
		JMenu mnVisitante = new JMenu("Visitante");
		mnVisitante.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				try {
					telas.getVisitante().setVisible(true);
					dispose();
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		menuBar.add(mnVisitante);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		MaskFormatter msk = new MaskFormatter("***.***.***-**");
		
		JPanel panel = new JPanel();
		panel.setForeground(new Color(165, 42, 42));
		panel.setBackground(new Color(0, 139, 139, 50));
		panel.setBounds(10, 11, 418, 237);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblCadastroDoFuncionario = new JLabel("Cadastro do Funcionario");
		lblCadastroDoFuncionario.setBounds(119, 11, 167, 14);
		panel.add(lblCadastroDoFuncionario);
		lblCadastroDoFuncionario.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		
		lblNome = new JLabel("Nome");
		lblNome.setBounds(10, 53, 46, 14);
		panel.add(lblNome);
		lblNome.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNome.setBackground(new Color(0, 0, 0));
		
		
		textFieldNome = new JTextField();
		textFieldNome.setBounds(55, 51, 336, 20);
		panel.add(textFieldNome);
		textFieldNome.setColumns(10);
		
		JLabel lblCpf = new JLabel("Cpf");
		lblCpf.setBounds(10, 95, 30, 14);
		panel.add(lblCpf);
		lblCpf.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		
		textFieldCpf = new JFormattedTextField(msk);
		textFieldCpf.setBounds(55, 93, 121, 20);
		panel.add(textFieldCpf);
		textFieldCpf.setColumns(10);
		
		textFieldMatri = new JTextField();
		textFieldMatri.setBounds(276, 93, 115, 20);
		panel.add(textFieldMatri);
		textFieldMatri.setColumns(10);
		
		JLabel lblMatricula = new JLabel("Matricula");
		lblMatricula.setBounds(201, 95, 65, 14);
		panel.add(lblMatricula);
		lblMatricula.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		textFieldCargo = new JTextField();
		textFieldCargo.setBounds(55, 136, 337, 20);
		panel.add(textFieldCargo);
		textFieldCargo.setColumns(10);
		
		JLabel lblCargo = new JLabel("Cargo");
		lblCargo.setBounds(10, 138, 46, 14);
		panel.add(lblCargo);
		lblCargo.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		btnCadastro = new JButton("Cadastrar");
		btnCadastro.setBounds(300, 190, 91, 23);
		panel.add(btnCadastro);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon("H:\\workspace\\SupportWatchful\\Imagens\\i=magem lois.jpg"));
		lblNewLabel.setBounds(0, 0, 443, 252);
		contentPane.add(lblNewLabel);
		btnCadastro.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				funci.setCargo(textFieldCargo.getText());
				funci.setCpf(textFieldCpf.getText());
				funci.setMatricula(textFieldMatri.getText());
				funci.setNome(textFieldNome.getText());
				
				
				try {
					controleFuncionario.salvar(funci);
					JOptionPane.showMessageDialog(null, "Funcionario cadastrado!!");
					textFieldCargo.setText("");
					textFieldCpf.setText("");
					textFieldMatri.setText("");
					textFieldNome.setText("");
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
				
				
				
				
				
			}
		});
	}
}
